package com.tfjybj.itoo.exam.provider.service.impl;


import com.dmsdbj.itoo.tool.base.service.impl.BaseServicePlusImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tfjybj.itoo.exam.entity.StudentScoreDetailEntity;
import com.tfjybj.itoo.exam.provider.dao.StudentScoreDetailDao;
import com.tfjybj.itoo.exam.provider.service.OnlineExamService;
import com.tfjybj.itoo.exam.provider.service.StudentScoreDetailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * StudentScoreDetailService接口实现类
 * ${base}表
 *
 * @author 任晓帅
 * @version 2.0.0
 * @since 2.0.0 2018-11-15 19:40:28
 */
@Service("studentScoreDetailService")
public class StudentScoreDetailServiceImpl extends BaseServicePlusImpl<StudentScoreDetailDao, StudentScoreDetailEntity> implements StudentScoreDetailService {

    /**
     * 打印日志相关
     */
    private static final Logger logger = LoggerFactory.getLogger(StudentScoreDetailServiceImpl.class);
	//region 模板生成
    @Resource
    private StudentScoreDetailDao studentScoreDetailDao;
    @Resource
    private OnlineExamService onlineExamService;

	 @Override
    public PageInfo<StudentScoreDetailEntity> queryByLikeStudentName(String studentName, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(studentScoreDetailDao.queryLikeStudentName(studentName));
    }
	//endregion

    /* **********************************以下为非模板生成的内容********************************* */

//    /**
//     * 根据试卷id+学生id回显手动判分部分的题目详情
//     * @param paperId   试卷id
//     * @param studentId 学生id
//     * @return 试卷详情
//     * @author 樊建华
//     * @since 2018年11月21日19:49:21
//     */
//
//    @Override
//    public ItooResult queryNotAutoJudeMainsDetails(String paperId, String studentId) {
//        if (StringUtils.isEmpty(paperId) || StringUtils.isEmpty(studentId)) {
//            return ItooResult.build("1111", "学号和试卷不能为空");
//        }
//        ExamPaperModel examPaperModel = onlineExamService.queryNotAutoJudeMains(studentId, paperId);
//        if (examPaperModel != null) {
//            queryQuestionTypeScore(studentId, paperId, examPaperModel);
//            return ItooResult.build("0000", "查询手动判分题型成功", examPaperModel);
//        } else {
//            return ItooResult.build("0000", "请确认此试卷存在手动判分题型");
//        }
//    }

    /**
     * 查询试卷中各个题目的得分情况
     *
     * @param studentId      学号
     * @param paperId        试卷id
     * @param examPaperModel 考试试卷
     * @return 逻辑判断标识
     */
//    private boolean queryQuestionTypeScore(String studentId, String paperId, ExamPaperModel examPaperModel) {
//        //2、查询试卷中各个题目的得分情况
//
//        List<StudentScoreDetailEntity> studentScoreDetailEntityList = studentScoreDetailDao.queryAll();
//        if (CollectionUtils.isNotEmpty(studentScoreDetailEntityList)) {
//            StudentScoreDetailEntity studentScoreDetailEntity = studentScoreDetailEntityList.get(0);
//
//            List<QueryQuestionTypeModel> list;
//            try {
//                list = JacksonJsonUntil.jsonToList(studentScoreDetailEntity.getQuestionTypeScore(), QueryQuestionTypeModel.class);
//            } catch (IOException e) {
//                logger.error("题型详情json转换失败", e);
//                throw new ItooRuntimeException(e);
//            }
//            HashMap<String, Integer> map = new HashMap<>(16);
//            list.forEach(queryQuestionTypeModel -> map.put(queryQuestionTypeModel.getQuestionTypeId(), queryQuestionTypeModel.getSource()));
//            examPaperModel.getPaperQuestionTypeModelList().forEach(model -> model.setQuestionScore(map.get(model.getQuestionTypeId())));
//
//            //3、查询试卷学生总得分
//            examPaperModel.setPaperScore(studentScoreDetailEntity.getStudentScore());
//            return true;
//        }
//        return false;
//    }


}
